package com.lisp.algorithm.test.sort;

import java.util.Arrays;

public class InsertionSort {

	public static void main(String[] args) {
		int data[] = {10, 9, 18, 30, 24, 2, 1, 100, 28, 43, 2, 7, 9, 190, 9, 9};
		insertionSort(data);
		System.out.println(Arrays.toString(data));
	}
	
	private static void insertionSort(int data[]) {
		for(int i=1; i<data.length; i++) {
			int val = data[i];
			for(int j=i-1; j>=0; j--) {
				if(data[j] > val) {
					int tmp = data[j];
					data[j] = data[j+1];
					data[j+1] = tmp;
				} else {
					data[j+1] = val;
					break;
				}
			}
		}
	}
}
